<?php				
	interface block_class_info
	{		
		function getBlockList($BlockCode,$BlockName);
		function getRoomList($BlockCode);
		function getRoomList_Floor($BlockCode,$Floor);
		function getRoomInfo($RoomID);
		function getFloorList($BlockCode);
		function getRoomIDByFloor($BlockCode,$FloorCode);
	}
	
	class block_class implements block_class_info
	{
		function block_class()
		{
			@session_start(); 
			require_once('../../lib/'.'BaseDir.inc.htm');
			require_once(EIU_LIB.'DBCommon.class.htm');					
		}
			
		function getBlockList($BlockCode,$BlockName){

			$oDB = new DBCommon();
			$conn =  $oDB->stl_openConn();
									
			$q = "
				SELECT BlockID,BlockCode,BlockName
				FROM block_tbl 
				WHERE 					
					BlockCode LIKE '%".$BlockCode."%' AND 
					BlockName LIKE '%".$BlockName."%' AND 					
					isDeleted=0 ORDER BY `BlockName` ASC
			";
			//echo $q;
			$rs = $oDB->stl_db_select($q, $conn);
			
			$oDB->stl_closeConn($conn);
			
			if($rs)	return $rs;
			else return false;		
		}		
		
		function getRoomList($BlockCode){

			$oDB = new DBCommon();
			$conn =  $oDB->stl_openConn();
									
			$q = "
				SELECT RoomID,RoomCode,BlockID,RoomName
				FROM room_tbl 
				WHERE 					
					BlockID = '".$BlockCode."' AND								
					isDeleted=0 ORDER BY `RoomName`
			";
			//echo $q;
			$rs = $oDB->stl_db_select($q, $conn);
			
			$oDB->stl_closeConn($conn);
			
			if($rs)	return $rs;
			else return false;		
		}	
		
		function getRoomList_Floor($BlockCode,$Floor){

			$oDB = new DBCommon();
			$conn =  $oDB->stl_openConn();
									
			$q = "
				SELECT RoomID,RoomCode,BlockID,RoomName
				FROM `room_tbl`
				WHERE 					
					`BlockID` = '".$BlockCode."' AND								
					LEFT(`RoomCode`,1) LIKE '".$Floor."%' AND								
					`isDeleted` = 0 ORDER BY `RoomID`
			";
			//echo $q;
			$rs = $oDB->stl_db_select($q, $conn);
			
			$oDB->stl_closeConn($conn);
			
			if($rs)	return $rs;
			else return false;		
		}	
		
		function getRoomInfo($RoomID)
		{
			$oDB = new DBCommon();
			$conn =  $oDB->stl_openConn();
									
			$q = "
				SELECT RoomTBL.RoomID,RoomTBL.RoomCode,RoomTBL.BlockID,RoomTBL.RoomName,block_tbl.BlockName,block_tbl.BlockCode
				FROM (
					SELECT RoomID,RoomCode,BlockID,RoomName
					FROM room_tbl 
					WHERE 
							RoomID = '".$RoomID."' AND								
							isDeleted=0
				) AS RoomTBL LEFT JOIN block_tbl ON RoomTBL.BlockID = block_tbl.BlockID
				WHERE 1
			";
			//echo $q;
			$rs = $oDB->stl_db_select($q, $conn);
			
			$oDB->stl_closeConn($conn);
			
			if($rs)	return $rs;
			else return false;
		}
		
		function getFloorList($BlockCode)
		{
			$oDB = new DBCommon();
			$conn =  $oDB->stl_openConn();
									
			$q = "
				SELECT DISTINCT LEFT(RoomCode,1) As Floor
				FROM room_tbl 
				WHERE 					
					BlockID = '".$BlockCode."' AND								
					isDeleted=0 ORDER BY `RoomName`
			";
			//echo $q;
			$rs = $oDB->stl_db_select($q, $conn);
			
			$oDB->stl_closeConn($conn);
			
			if($rs)	return $rs;
			else return false;
		}
		
		function getRoomIDByFloor($BlockCode,$FloorCode)
		{
			$oDB = new DBCommon();
			$conn =  $oDB->stl_openConn();
									
			$q = "
				SELECT `RoomID`
				FROM `room_tbl`
				WHERE 					
					`BlockID` = '".$BlockCode."' AND								
					`RoomCode` LIKE '".$FloorCode."%' AND								
					`isDeleted` = 0 ORDER BY `RoomID`
			";
			//echo $q;
			$rs = $oDB->stl_db_select($q, $conn);
			
			$oDB->stl_closeConn($conn);
			
			if($rs)	return $rs;
			else return false;
		}
		
	}
?>